package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.Dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.CheckItemService;
import com.itheima.service.MemberService;
import com.itheima.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 会员实现类
 */

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    public MemberDao memberDao;

    //根据电话号码查询会员
    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }
    //注册会员
    @Override
    public void add(Member member) {
        String password = member.getPassword();
        if(password!=null){
            password= MD5Utils.md5(password);
            member.setPassword(password);
        }
        memberDao.add(member);
    }
    //折线图
    @Override
    public List<Integer> findMemberCountByMonths(List<String> months) {
        List<Integer> list=new ArrayList<>();
        for (String m : months) {
            Integer count = memberDao.findMemberCountBeforeDate(m);
            list.add(count);
        }
        return list;
    }


}
